old_posts/2018-6-27-How to use Azure Container Registry for a Multi-container Web App.html (65 lines of code) (raw):
---
layout: post
hide_excerpt: true
---
<html><head>
<meta charset="utf-8"/>
</head>
<body>
<div id="page">
<a class="url fn n profile-usercard-hover" href="https://social.msdn.microsoft.com/profile/Yi Liao MSFT" target="_blank">Yi Liao MSFT</a>
<time> 6/27/2018 12:10:43 PM</time>
<hr/>
<div id="content">Back in May at Microsoft Build, we announced the public preview of Multi-Container Web App, which supports the ability for you to deploy multiple Docker images to Web App for Containers. All you have to do is bring your Docker Compose or Kubernetes Config file when creating a new web app. (Here are instructions to get started with <a href="https://docs.microsoft.com/azure/app-service/containers/tutorial-multi-container-app">Multi-Container</a> Web App).
Since we launched public preview, one of the most frequently asked questions that we've received is: "How do I configure Azure Container Registry with Multi-Container?"
Let me walk you through a quick tutorial that uses Azure Container Registry with Multi-Container.
<h2>Configure Your Docker Compose/Kubernetes File</h2>
To create a Multi-Container web app, you first need a Docker Compose or Kubernetes Config yml file. This is basically a definition file that describes a Multi-Container web app. Because we will be using Azure Container Registry (ACR), notice that the Docker Compose file has the ACR image repos in the file. The image with "ports: - 80:80" is the main container that exposed to Internet.
Here is a sample Docker Compose file:
<pre>version: '3'
services:
web:
image: [azure-container-registry-name].azurecr.io/flaskapp
ports:
– 80:80
redis:
image: [azure-container-registry-name].azurecr.io/redis:alpine</pre>
If this Docker Compose file looks familiar, it is <strong>actually the same as the Docker Compose file in the Quickstart</strong> that you can use when creating a Multi-Container app (with DockerHub), with the exception of the ACR modifications.
<a href="{{ site.baseurl }}/media/2018/06/2018-06-27_15h13_31.png"><img alt="" class="alignnone size-large wp-image-9015" height="362" src="{{ site.baseurl }}/media/2018/06/2018-06-27_15h13_31-1024x422.png" width="879"/></a>
<h2>Adding the App Settings</h2>
After you uploaded your Docker Compose file and clicked create, you will have to make sure App Service can access Azure Container Registry by adding the following App settings in the App Service portal:
<pre> DOCKER_REGISTRY_SERVER_USERNAME = [azure-container-registry-name]
DOCKER_REGISTRY_SERVER_URL = [azure-container-registry-name].azurecr.io
DOCKER_REGISTRY_SERVER_PASSWORD = [password]</pre>
<b>Note:</b> please make sure to enable admin access in the Azure Container Registry Server settings.
<h2>Limitations</h2>
All Docker images in the same Docker Compose or Kubernetes Config yml file <strong>need to come from the same Azure Container Registry</strong> <strong>server</strong>. This means that you may have to pull down popular images (such as nginx and Redis) from DockerHub, and tag it for ACR then push to your ACR registry server.
Further limitations on Docker Compose/Kube Config configuration options are documented <a href="https://docs.microsoft.com/en-us/azure/app-service/containers/tutorial-multi-container-app#create-a-docker-compose-app">here</a>.
<h2>Checking Your Logs</h2>
After the web app is restarted, you should see logs similar to the ones below in Container settings or in Kudu. (Kudu is where you can view all your Docker logs and is your source control management site. Kudu can be accessed via [your web app name].SCM.azurewebsites.net or under "Advanced Tools" in the left-hand menu).
<pre>2018-06-19 19:26:33.419 ERROR – multi-container unit was not started successfully
2018-06-19 19:26:33.422 INFO – Container logs from yili-multicontainer-acr-01_web_0 =
2018-06-19 19:29:42.691 INFO – Starting multi-container app, configuration =
version: '3'
services:
# this image repo’s source come from “Get started with Docker Compose” on docker.com
web:
image: [azure-container-registry-name].azurecr.io/flaskapp
ports:
– 80:80
redis:
image: [azure-container-registry-name].azurecr.io/redis:alpine
2018-06-19 19:30:14.621 INFO – Starting container for site
2018-06-19 19:30:14.622 INFO – docker run -d -p 55955:80 –name yili-multicontainer-acr-01_web_0 -e WEBSITE_SITE_NAME=yili-multicontainer-acr-01 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_INSTANCE_ID=6cc2f742b7330fbd63a5e79967ed9ee7904bb9d93c7ca7843312788a4c2bc622 yiliacr05.azurecr.io/flaskapp
2018-06-19 19:30:14.622 INFO – Logging is not enabled for this container.
Please use<span> </span><a href="https://aka.ms/linux-diagnostics">https://aka.ms/linux-diagnostics</a><span> </span>to enable logging to see container logs here.
2018-06-19 19:30:22.542 INFO – Starting container for site
2018-06-19 19:30:22.543 INFO – docker run -d -p 0:6379 –name yili-multicontainer-acr-01_redis_0 -e WEBSITE_SITE_NAME=yili-multicontainer-acr-01 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_INSTANCE_ID=6cc2f742b7330fbd63a5e79967ed9ee7904bb9d93c7ca7843312788a4c2bc622 yiliacr05.azurecr.io/redis:alpine
2018-06-19 19:30:22.544 INFO – Logging is not enabled for this container.
Please use<span> </span><a href="https://aka.ms/linux-diagnostics">https://aka.ms/linux-diagnostics</a><span> </span>to enable logging to see container logs here.
2018-06-19 19:30:30.750 INFO – Started multi-container app
2018-06-19 19:30:30.778 INFO – Container yili-multicontainer-acr-01_web_0 for site yili-multicontainer-acr-01 initialized successfully.</pre></div>
</div></body>
<script src="{{ site.baseurl }}/resource/jquery-1.12.1.min.js" type="text/javascript"></script>
<script src="{{ site.baseurl }}/resource/replace.js" type="text/javascript"></script>
</html>